<template>
  <div class="app-container">
    <eHeader :param-bean="paramBean" :sup_this="sup_this" />
    <eForm ref="form" :sup_this="sup_this" />
    <!--表格渲染-->
    <DataGridTable
      v-loading="loading"
      ref="mainTable"
      :sup_this="sup_this"
      :data="data.rtnList"
      :total="total"
      :show-row-complex-number="true"
      :show-cell-class="true"
      :all-define-columns="['formName','formType','oaMenuName','selfStateName','lastUpdateDate']"
      grid-id="formSetMngMainGridId"
      @toViewHistory="toViewHistory"
      @selection-change="handleGridSelectionChange">
      <DataGridColumnSlot :show-overflow-tooltip="true" prop="funProcessName" label="业务类型" width="200px">
        <template slot-scope="scope">
          <edit :data="scope.row" :sup_this="sup_this" />
        </template>
      </DataGridColumnSlot>
      <DataGridColumn slot="formName" prop="formName" label="表单名称"/>
      <DataGridColumnSlot slot="formType" prop="formType" label="表单类型" align="center">
        <template slot-scope="scope">
          <div v-for="item in dicts.form_type" :key="item.id">
            <el-tag v-if="scope.row.formType == item.dictCode">{{ item.dictName }}</el-tag>
          </div>
        </template>
      </DataGridColumnSlot>
      <DataGridColumn slot="oaMenuName" prop="oaMenuName" label="OA菜单名"/>
      <DataGridColumn slot="selfStateName" prop="selfStateName" label="状态"/>
      <DataGridColumnSlot slot="lastUpdateDate" :show-overflow-tooltip="true" prop="lastUpdateDate" label="更新日期">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.lastUpdateDate) }}</span>
        </template>
      </DataGridColumnSlot>
      <el-table-column v-if="checkPermission(['SYS_ADMIN','COMMON_ADMIN','FORM_SET_ALL','FORM_SET_CREATE','FORM_SET_CHANGE'])" label="操作" width="300px" align="center">
        <template slot-scope="scope">
          <el-button type="primary" size="mini">
            <router-link :to="'/formdesign/home?formId=' + scope.row.id + '&sysGenCode=' + scope.row.sysGenCode" target="_blank">表单设计</router-link>
          </el-button>
          <el-button v-if="scope.row.funProcess !== '40'" :loading="privLoading" type="primary" size="mini" @click="privSetting(scope.row)">控件权限定义</el-button>
        </template>
      </el-table-column>
    </DataGridTable>
    <historyList ref="historyList" :sup_this="sup_this" />
    <privFieldList ref="privFieldList" :sup_this="sup_this" />
  </div>
</template>

<script>
import checkPermission from '@/utils/permission'
import initData from '@/mixins/initData'
import { loadDataUrl } from '@/api/system/formSet'
import { parseTime } from '@/utils/index'
import eHeader from './module/header'
import edit from './module/edit'
import eForm from './module/form'
import historyList from './module/historyList'
import PrivFieldList from './module/privFieldList'

export default {
  components: { PrivFieldList, eHeader, eForm, edit, historyList },
  mixins: [initData],
  dictTypes: ['form_type'],
  data() {
    return {
      delLoading: false,
      privLoading: false,
      sup_this: this
    }
  },
  created() {
    this.url = loadDataUrl()
    this.$nextTick(() => {
      this.init()
    })
  },
  methods: {
    parseTime,
    checkPermission,
    beforeInit() {
      return true
    },
    privSetting(row) {
      const _this = this.$refs.privFieldList
      _this.busMainData = row
      _this.loadFieldPrivData(row.id)
      _this.dialog = true
    },
    toViewHistory(row) {
      this.openViewHistory(row, 'historyList')
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss">
  .role-span {
    font-weight: bold;color: #303133;
    font-size: 15px;
  }
</style>
